package de.westranger.forex.trading.genetic.allel.operator;

import java.text.ParseException;

public enum LogicalOperatorType {
	AND(0), OR(1), NAND(2), NOR(3), XOR(4), XNOR(5) ,DO_NOT_USE_ME(666), AND_NL(6), AND_NR(7), OR_NL(8), OR_NR(9), NAND_NL(10), NAND_NR(11), NOR_NL(12), NOR_NR(13);

	private final int value;

	private LogicalOperatorType(final int value) {
		this.value = value;
	}

	public final int getValue() {
		return this.value;
	}
	
	public static final LogicalOperatorType parse(final int value) throws ParseException {
		LogicalOperatorType termSym;
		switch (value) {
		case 0:
			termSym = LogicalOperatorType.AND;
			break;
		case 6:
			termSym = LogicalOperatorType.AND_NL;
			break;
		case 7:
			termSym = LogicalOperatorType.AND_NR;
			break;
		case 1:
			termSym = LogicalOperatorType.OR;
			break;
		case 8:
			termSym = LogicalOperatorType.OR_NL;
			break;
		case 9:
			termSym = LogicalOperatorType.OR_NR;
			break;
		case 2:
			termSym = LogicalOperatorType.NAND;
			break;
		case 10:
			termSym = LogicalOperatorType.NAND_NL;
			break;
		case 11:
			termSym = LogicalOperatorType.NAND_NR;
			break;
		case 3:
			termSym = LogicalOperatorType.NOR;
			break;
		case 12:
			termSym = LogicalOperatorType.NOR_NL;
			break;
		case 13:
			termSym = LogicalOperatorType.NOR_NR;
			break;
		case 4:
			termSym = LogicalOperatorType.XOR;
			break;
		case 5:
			termSym = LogicalOperatorType.XNOR;
			break;
		case 666:
			termSym = LogicalOperatorType.DO_NOT_USE_ME;
			break;			
		default:
			throw new ParseException(
					"could not parse LogicalOperatorType with the value " + value, 0);
		}
		return termSym;
	}
}
